package com.singzi.leetcode.jianzhiOffer2;

import java.util.Stack;

public class T0036 {
    public static void main(String[] args) {
        Solution0036 solution0036 = new Solution0036();
        solution0036.evalRPN(new String[]{"10","6","9","3","+","-11","*","/","*","17","+","5","+"});
    }
}
class Solution0036 {
    public int evalRPN(String[] tokens) {

        Stack<Integer> stack = new Stack<>();
        for(String token:tokens){
            try {
                int a = Integer.parseInt(token);  //异常点
                stack.push(a);
            } catch (Exception e) {
                int a = stack.pop();
                int b = stack.pop();
                if(token.equals("+")){
                    a = a+b;
                }
                if(token.equals("-")){
                    a = a-b;

                }
                if(token.equals("*")){
                    a = a*b;

                }
                if(token.equals("/")){
                    a = a/b;
                }
                stack.push(a);
            }
        }
        return stack.pop();
    }
}